﻿@model ScrumProject.ViewModels.PostsViewModel


@{
    ViewBag.Title = "Index";

    ScrumProject.Models.PostRepository pr = new ScrumProject.Models.PostRepository();
}

<script type="text/javascript">

    $("#submit").click(function(){
        $("#show").valueOf($("#post").valueOf());
    });

</script>

<h2>Project Wall</h2>

@using (Html.BeginForm())
{
    @Html.ValidationSummary(true)
    <fieldset>
        
        <table class="table">
    
            <tr>
                <br />
                <br />
                <td style="width:120px">
                </td>
                <td><center>
                    <h5>Post a new message   </h5></center>
                </td>    
                <td>
                    <div class="editor-field">
                        @Html.TextAreaFor(model => model.Post.Content, new { rows = 10, cols = 40, name = "post", style = "width: 500px; height: 100px;" })
                    </div>
                </td>
            </tr>
            <tr>
                <td></td>
                <td></td>
                <td>
                    <input type="submit" name="submit" value="Post to a wall" class="btn" onclick="display()" id="submit" />
                </td>
            </tr>
        </table>
    </fieldset>
   
    @*<div>
        @if (TempData["message"] != null)
        { 
            <h4>@TempData["user"]</h4>
            <div>@TempData["message"]</div>
        }
    </div>*@
    <fieldset style="text-align:left; font-size:12px; line-height:25px; font-weight:bold; 
                    width:50%; margin:  0px auto; display:block;">
    
        @foreach (var item in Model.Posts)
        {
            string[] testi = item.Content.Split('\n');
            string username = pr.GetUserWhoWrotePost(item.UserId);
            @Html.HiddenFor(model => item.Id)
            <ul style="list-style: none">
                    <li style="padding-top: 0pt; background-color: 	#CDD1C1;">
                        <label>
                            <div>
                                <strong>@username</strong>                                
                                <br />
                                <small style="color: #694251">
                                    @if (User.IsInRole("admin"))
                                    {
                                        @Html.ActionLink("Delete", "DeletePost", new { id = item.Id }) 
                                    }
                                    @item.Time
                                </small>
                            </div>
                        </label>
                        <div style="text-align:left; margin-left:170px">
                            <div>
                                @foreach (string st in testi)
                                {
                                    @st;<br />
                                }
                            </div>
                            
                            <hr />
                            
                            <div style="text-align:left">
                                @foreach (var comment in item.Comments)
                                {
                                    string[] commi = comment.Content.Split('\n'); 
                                    @Html.HiddenFor(model => comment.Id)
                                    <ul style="list-style: none">
                                        <li style="padding-top: 0pt; background-color: 	#CDD1C1;">
                                                
                                            <div style="text-align:left">
                                                    
                                                <div style="font-weight:normal">
                                                    <strong>@username</strong>
                                                    @foreach (string st in commi)
                                                    {
                                                    @st;<br />
                                                    }
                                                </div>
                                                <small style="color: #694251">
                                                    @if(comment.UserId == (User as ScrumProject.Models.CustomPrincipal).UserId){
                                                        @Html.ActionLink("Delete", "DeleteComment", new { cid = comment.Id }) 
                                                    }
                                                    @comment.Time
                                                </small>
                                            </div>
                                        </li>
                                    </ul>
                                }
                            </div>
                            
                            <div style="text-align:right; margin-right:20px">
                                @Html.ActionLink("Post comment", "AddComment", new { postId = item.Id })
                            </div>

                        </div>
            </li>
    </ul>
        }
    
    </fieldset>
}


